<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<!--
  This file is a part of the open-eBackup project.
  This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
  If a copy of the MPL was not distributed with this file, You can obtain one at
  http://mozilla.org/MPL/2.0/.
  
  Copyright (c) [2024] Huawei Technologies Co.,Ltd.
  
  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
  EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
  MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
  -->

<html lang="zh-cn" xml:lang="zh-cn">
 <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="DC.Type" content="topic">
  <meta name="DC.Title" content="以单节点副本集的形式开启Oplog">
  <meta name="DC.Format" content="XHTML">
  <meta name="DC.Identifier" content="ZH-CN_TOPIC_0000002015810301">
  <meta name="DC.Language" content="zh-cn">
  <link rel="stylesheet" type="text/css" href="public_sys-resources/commonltr.css">
  <title>以单节点副本集的形式开启Oplog</title>
 </head>
 <body style="clear:both; padding-left:10px; padding-top:5px; padding-right:5px; padding-bottom:5px">
  <a name="ZH-CN_TOPIC_0000002015810301"></a><a name="ZH-CN_TOPIC_0000002015810301"></a>
  <h1 class="topictitle1">以单节点副本集的形式开启Oplog</h1>
  <div>
   <div class="section">
    <h4 class="sectiontitle">操作步骤</h4>
    <ol>
     <li><span>登录MongoDB实例所在主机。</span></li>
     <li id="ZH-CN_TOPIC_0000002015810301__li122752027152315"><a name="ZH-CN_TOPIC_0000002015810301__li122752027152315"></a><a name="li122752027152315"></a><span>执行下面命令，登录MongoDB数据库。</span><p></p><pre class="screen"><strong>mongo --port </strong><em>数据库端口</em></pre>
      <div class="note">
       <img src="public_sys-resources/note_3.0-zh-cn.png"><span class="notetitle"> </span>
       <div class="notebody">
        <p>执行<strong>cat /</strong><em>数据库安装目录</em><strong>/single/mongod.conf</strong>获取数据库端口。</p>
       </div>
      </div> <p></p></li>
     <li id="ZH-CN_TOPIC_0000002015810301__li1227562712313"><a name="ZH-CN_TOPIC_0000002015810301__li1227562712313"></a><a name="li1227562712313"></a><span>执行<strong>use local</strong>切换到local用户。执行下面命令，查询MongoDB数据库的表信息。</span><p></p><p>若回显中含有Oplog.rs则表示已开启Oplog，操作结束。否则需要继续执行后续操作开启Oplog。</p> <pre class="screen"><strong>show table</strong></pre> <p>回显类似如下：</p> <pre class="screen">oplog.rs
replset.election
replset.minvalid
replset.oplogTruncateAfterPoint
startup_log
system.replset
system.rollback.id</pre> <p></p></li>
     <li><span>返回登录MongoDB实例所在主机。</span></li>
     <li><span>执行下面命令进入实例配置文件，配置数据库实例。在配置文件中添加一行<strong>replSet=</strong><em>single_node_repl_name</em>（自定义单节点副本集名称）。</span><p></p><pre class="screen"><strong>vi /</strong><em>数据库安装目录</em><strong>/single/mongod.conf</strong></pre> <p></p></li>
     <li><span>执行下面命令重启MongoDB数据库。</span><p></p><pre class="screen"><strong>systemctl restart mongod</strong></pre> <p></p></li>
     <li><span>执行下面命令进行初始化操作。</span><p></p><pre class="screen"><strong>rs.initiate({ _id: "</strong><em>副本集名称</em><strong>", members: [{_id:0,host:"</strong><em>服务器的IP</em><strong>:</strong><em>Mongo的端口号</em><strong>"}]})</strong></pre>
      <div class="p">
       例如：
       <pre class="screen"><strong>rs.initiate({ _id: "single", members: [{_id:0,host:"192.168.144.249:27017"}]})</strong></pre>
      </div> <p></p></li>
     <li><span>执行<a href="#ZH-CN_TOPIC_0000002015810301__li122752027152315">2</a>-<a href="#ZH-CN_TOPIC_0000002015810301__li1227562712313">3</a>查询是否以单节点副本集的形式开启Oplog。</span></li>
    </ol>
   </div>
   <p></p>
  </div>
 </body>
</html>